winsafe\mf\com_interfaces/
imfattributes.rs

1#![allow(non_camel_case_types, non_snake_case)]
2
3use crate::co;
4use crate::decl::*;
5use crate::guard::*;
6use crate::kernel::privs::*;
7use crate::mf::vts::*;
8use crate::ole::privs::*;
9use crate::prelude::*;
10
11com_interface! { IMFAttributes: "2cd2d921-c447-44a7-a13c-4adabfc247e3";
12	/// [`IMFAttributes`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nn-mfobjects-imfattributes)
13	/// COM interface.
14	///
15	/// Automatically calls
16	/// [`Release`](https://learn.microsoft.com/en-us/windows/win32/api/unknwn/nf-unknwn-iunknown-release)
17	/// when the object goes out of scope.
18}
19
20impl mf_IMFAttributes for IMFAttributes {}
21
22/// This trait is enabled with the `mf` feature, and provides methods for
23/// [`IMFAttributes`](crate::IMFAttributes).
24///
25/// Prefer importing this trait through the prelude:
26///
27/// ```no_run
28/// use winsafe::prelude::*;
29/// ```
30pub trait mf_IMFAttributes: ole_IUnknown {
31	/// [`IMFAttributes::Compare`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-compare)
32	/// method.
33	#[must_use]
34	fn Compare(
35		&self,
36		theirs: &impl mf_IMFAttributes,
37		match_type: co::MF_ATTRIBUTES_MATCH,
38	) -> HrResult<bool> {
39		let mut res = 0;
40		ok_to_hrresult(unsafe {
41			(vt::<IMFAttributesVT>(self).Compare)(
42				self.ptr(),
43				theirs.ptr(),
44				match_type.raw(),
45				&mut res,
46			)
47		})
48		.map(|_| res != 0)
49	}
50
51	/// [`IMFAttributes::CompareItem`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-compareitem)
52	/// method.
53	#[must_use]
54	fn CompareItem(&self, guid_key: &GUID, value: &PropVariant) -> HrResult<bool> {
55		let mut res = 0;
56		ok_to_hrresult(unsafe {
57			(vt::<IMFAttributesVT>(self).CompareItem)(
58				self.ptr(),
59				pcvoid(guid_key),
60				pcvoid(&value.to_raw()?),
61				&mut res,
62			)
63		})
64		.map(|_| res != 0)
65	}
66
67	/// [`IMFAttributes::CopyAllItems`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-copyallitems)
68	/// method.
69	fn CopyAllItems(&self, dest: &impl mf_IMFAttributes) -> HrResult<()> {
70		ok_to_hrresult(unsafe {
71			(vt::<IMFAttributesVT>(self).CopyAllItems)(self.ptr(), dest.ptr())
72		})
73	}
74
75	fn_com_noparm! { DeleteAllItems: IMFAttributesVT;
76		/// [`IMFAttributes::DeleteAllItems`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-deleteallitems)
77		/// method.
78	}
79
80	/// [`IMFAttributes::DeleteItem`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-deleteitem)
81	/// method.
82	fn DeleteItem(&self, guid_key: &GUID) -> HrResult<()> {
83		ok_to_hrresult(unsafe {
84			(vt::<IMFAttributesVT>(self).DeleteItem)(self.ptr(), pcvoid(guid_key))
85		})
86	}
87
88	/// [`IMFAttributes::GetAllocatedBlob`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getallocatedblob)
89	/// method.
90	///
91	/// Note that this method allocates the buffer twice, whereas
92	/// [`IMFAttributes::GetBlob`](crate::prelude::mf_IMFAttributes::GetBlob)
93	/// allocates only once, thus being more efficient.
94	#[must_use]
95	fn GetAllocatedBlob(&self, guid_key: &GUID) -> HrResult<Vec<u8>> {
96		let mut pbuf = std::ptr::null_mut::<u8>();
97		let mut sz = 0u32;
98
99		ok_to_hrresult(unsafe {
100			(vt::<IMFAttributesVT>(self).GetAllocatedBlob)(
101				self.ptr(),
102				pcvoid(guid_key),
103				&mut pbuf,
104				&mut sz,
105			)
106		})
107		.map(|_| {
108			let raw = unsafe { CoTaskMemFreeGuard::new(pbuf as *mut _, sz as _) };
109			raw.as_slice().to_vec()
110		})
111	}
112
113	/// [`IMFAttributes::GetAllocatedString`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getallocatedstring)
114	/// method.
115	///
116	/// Note that this method allocates the buffer twice, whereas
117	/// [`IMFAttributes::GetString`](crate::prelude::mf_IMFAttributes::GetString)
118	/// allocates only once, thus being more efficient.
119	#[must_use]
120	fn GetAllocatedString(&self, guid_key: &GUID) -> HrResult<String> {
121		let mut pstr = std::ptr::null_mut::<u16>();
122		let mut nchars = 0u32;
123
124		ok_to_hrresult(unsafe {
125			(vt::<IMFAttributesVT>(self).GetAllocatedString)(
126				self.ptr(),
127				pcvoid(guid_key),
128				&mut pstr,
129				&mut nchars,
130			)
131		})
132		.map(|_| htaskmem_ptr_to_str(pstr))
133	}
134
135	/// [`IMFAttributes::GetBlob`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getblob)
136	/// method.
137	///
138	/// Calls
139	/// [`IMFAttributes::GetBlobSize`](crate::prelude::mf_IMFAttributes::GetBlobSize)
140	/// to alloc the buffer.
141	#[must_use]
142	fn GetBlob(&self, guid_key: &GUID) -> HrResult<Vec<u8>> {
143		let sz = self.GetBlobSize(guid_key)?;
144		let mut buf = vec![0u8; sz as _];
145
146		ok_to_hrresult(unsafe {
147			(vt::<IMFAttributesVT>(self).GetBlob)(
148				self.ptr(),
149				pcvoid(guid_key),
150				buf.as_mut_ptr(),
151				sz,
152				std::ptr::null_mut(),
153			)
154		})
155		.map(|_| buf)
156	}
157
158	/// [`IMFAttributes::GetBlobSize`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getblobsize)
159	/// method.
160	#[must_use]
161	fn GetBlobSize(&self, guid_key: &GUID) -> HrResult<u32> {
162		let mut sz = 0u32;
163		ok_to_hrresult(unsafe {
164			(vt::<IMFAttributesVT>(self).GetBlobSize)(self.ptr(), pcvoid(guid_key), &mut sz)
165		})
166		.map(|_| sz)
167	}
168
169	/// [`IMFAttributes::GetCount`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getcount)
170	/// method.
171	#[must_use]
172	fn GetCount(&self) -> HrResult<u32> {
173		let mut count = 0u32;
174		ok_to_hrresult(unsafe { (vt::<IMFAttributesVT>(self).GetCount)(self.ptr(), &mut count) })
175			.map(|_| count)
176	}
177
178	/// [`IMFAttributes::GetDouble`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getdouble)
179	/// method.
180	#[must_use]
181	fn GetDouble(&self, guid_key: &GUID) -> HrResult<f64> {
182		let mut value = f64::default();
183		ok_to_hrresult(unsafe {
184			(vt::<IMFAttributesVT>(self).GetDouble)(self.ptr(), pcvoid(guid_key), &mut value)
185		})
186		.map(|_| value)
187	}
188
189	/// [`IMFAttributes::GetGUID`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getguid)
190	/// method.
191	#[must_use]
192	fn GetGUID(&self, guid_key: &GUID) -> HrResult<GUID> {
193		let mut value = GUID::default();
194		ok_to_hrresult(unsafe {
195			(vt::<IMFAttributesVT>(self).GetGUID)(self.ptr(), pcvoid(guid_key), pvoid(&mut value))
196		})
197		.map(|_| value)
198	}
199
200	/// [`IMFAttributes::GetItem`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getitem)
201	/// method.
202	#[must_use]
203	fn GetItem(&self, guid_key: &GUID) -> HrResult<PropVariant> {
204		let mut value = PROPVARIANT::default();
205		ok_to_hrresult(unsafe {
206			(vt::<IMFAttributesVT>(self).GetItem)(self.ptr(), pcvoid(guid_key), pvoid(&mut value))
207		})?;
208		PropVariant::from_raw(&value)
209	}
210
211	/// [`IMFAttributes::GetItemByIndex`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getitembyindex)
212	/// method.
213	#[must_use]
214	fn GetItemByIndex(&self, index: u32) -> HrResult<(GUID, PropVariant)> {
215		let mut guid = GUID::default();
216		let mut value = PROPVARIANT::default();
217
218		ok_to_hrresult(unsafe {
219			(vt::<IMFAttributesVT>(self).GetItemByIndex)(
220				self.ptr(),
221				index,
222				pvoid(&mut guid),
223				pvoid(&mut value),
224			)
225		})?;
226		Ok((guid, PropVariant::from_raw(&value)?))
227	}
228
229	/// [`IMFAttributes::GetItemType`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getitemtype)
230	/// method.
231	#[must_use]
232	fn GetItemType(&self, guid_key: &GUID) -> HrResult<co::MF_ATTRIBUTE> {
233		let mut ty = co::MF_ATTRIBUTE::default();
234		ok_to_hrresult(unsafe {
235			(vt::<IMFAttributesVT>(self).GetItemType)(self.ptr(), pcvoid(guid_key), ty.as_mut())
236		})
237		.map(|_| ty)
238	}
239
240	/// [`IMFAttributes::GetString`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getstring)
241	/// method.
242	///
243	/// Calls
244	/// [`IMFAttributes::GetStringLength`](crate::prelude::mf_IMFAttributes::GetStringLength)
245	/// to alloc the buffer.
246	#[must_use]
247	fn GetString(&self, guid_key: &GUID) -> HrResult<String> {
248		let len = self.GetStringLength(guid_key)? + 1;
249		let mut buf = WString::new_alloc_buf(len as _);
250
251		ok_to_hrresult(unsafe {
252			(vt::<IMFAttributesVT>(self).GetString)(
253				self.ptr(),
254				pcvoid(guid_key),
255				buf.as_mut_ptr(),
256				len,
257				std::ptr::null_mut(),
258			)
259		})
260		.map(|_| buf.to_string())
261	}
262
263	/// [`IMFAttributes::GetStringLength`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getstringlength)
264	/// method.
265	#[must_use]
266	fn GetStringLength(&self, guid_key: &GUID) -> HrResult<u32> {
267		let mut len = 0u32;
268		ok_to_hrresult(unsafe {
269			(vt::<IMFAttributesVT>(self).GetStringLength)(self.ptr(), pcvoid(guid_key), &mut len)
270		})
271		.map(|_| len)
272	}
273
274	/// [`IMFAttributes::GetUINT32`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getuint32)
275	/// method.
276	fn GetUINT32(&self, guid_key: &GUID) -> HrResult<u32> {
277		let mut value = 0u32;
278		ok_to_hrresult(unsafe {
279			(vt::<IMFAttributesVT>(self).GetUINT32)(self.ptr(), pcvoid(guid_key), &mut value)
280		})
281		.map(|_| value)
282	}
283
284	/// [`IMFAttributes::GetUINT64`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getuint64)
285	/// method.
286	fn GetUINT64(&self, guid_key: &GUID) -> HrResult<u64> {
287		let mut value = 0u64;
288		ok_to_hrresult(unsafe {
289			(vt::<IMFAttributesVT>(self).GetUINT64)(self.ptr(), pcvoid(guid_key), &mut value)
290		})
291		.map(|_| value)
292	}
293
294	/// [`IMFAttributes::GetUnknown`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getunknown)
295	/// method.
296	#[must_use]
297	fn GetUnknown<T>(&self, guid_key: &GUID) -> HrResult<T>
298	where
299		T: ole_IUnknown,
300	{
301		let mut queried = unsafe { T::null() };
302		ok_to_hrresult(unsafe {
303			(vt::<IMFAttributesVT>(self).GetUnknown)(
304				self.ptr(),
305				pcvoid(guid_key),
306				pcvoid(&T::IID),
307				queried.as_mut(),
308			)
309		})
310		.map(|_| queried)
311	}
312
313	fn_com_noparm! { LockStore: IMFAttributesVT;
314		/// [`IMFAttributes::LockStore`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-lockstore)
315		/// method.
316	}
317
318	/// [`IMFAttributes::SetBlob`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setblob)
319	/// method.
320	fn SetBlob(&self, guid_key: &GUID, buf: &[u8]) -> HrResult<()> {
321		ok_to_hrresult(unsafe {
322			(vt::<IMFAttributesVT>(self).SetBlob)(
323				self.ptr(),
324				pcvoid(guid_key),
325				vec_ptr(buf),
326				buf.len() as _,
327			)
328		})
329	}
330
331	/// [`IMFAttributes::SetDouble`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setdouble)
332	/// method.
333	fn SetDouble(&self, guid_key: &GUID, value: f64) -> HrResult<()> {
334		ok_to_hrresult(unsafe {
335			(vt::<IMFAttributesVT>(self).SetDouble)(self.ptr(), pcvoid(guid_key), value)
336		})
337	}
338
339	/// [`IMFAttributes::SetGUID`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setguid)
340	/// method.
341	fn SetGUID(&self, guid_key: &GUID, value: &GUID) -> HrResult<()> {
342		ok_to_hrresult(unsafe {
343			(vt::<IMFAttributesVT>(self).SetGUID)(self.ptr(), pcvoid(guid_key), pcvoid(value))
344		})
345	}
346
347	/// [`IMFAttributes::SetItem`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setitem)
348	/// method.
349	fn SetItem(&self, guid_key: &GUID, value: &PropVariant) -> HrResult<()> {
350		ok_to_hrresult(unsafe {
351			(vt::<IMFAttributesVT>(self).SetItem)(
352				self.ptr(),
353				pcvoid(guid_key),
354				pcvoid(&value.to_raw()?),
355			)
356		})
357	}
358
359	/// [`IMFAttributes::SetString`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setstring)
360	/// method.
361	fn SetString(&self, guid_key: &GUID, value: &str) -> HrResult<()> {
362		ok_to_hrresult(unsafe {
363			(vt::<IMFAttributesVT>(self).SetString)(
364				self.ptr(),
365				pcvoid(guid_key),
366				WString::from_str(value).as_ptr(),
367			)
368		})
369	}
370
371	/// [`IMFAttributes::SetUINT32`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setuint32)
372	/// method.
373	fn SetUINT32(&self, guid_key: &GUID, value: u32) -> HrResult<()> {
374		ok_to_hrresult(unsafe {
375			(vt::<IMFAttributesVT>(self).SetUINT32)(self.ptr(), pcvoid(guid_key), value)
376		})
377	}
378
379	/// [`IMFAttributes::SetUINT64`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setuint64)
380	/// method.
381	fn SetUINT64(&self, guid_key: &GUID, value: u64) -> HrResult<()> {
382		ok_to_hrresult(unsafe {
383			(vt::<IMFAttributesVT>(self).SetUINT64)(self.ptr(), pcvoid(guid_key), value)
384		})
385	}
386
387	/// [`IMFAttributes::SetUnknown`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setunknown)
388	/// method.
389	fn SetUnknown(&self, guid_key: &GUID, value: &impl ole_IUnknown) -> HrResult<()> {
390		ok_to_hrresult(unsafe {
391			(vt::<IMFAttributesVT>(self).SetUnknown)(self.ptr(), pcvoid(guid_key), value.ptr())
392		})
393	}
394
395	fn_com_noparm! { UnlockStore: IMFAttributesVT;
396		/// [`IMFAttributes::UnlockStore`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-unlockstore)
397		/// method.
398	}
399}